package com.lzw.blog.admin.controller;

import com.lzw.blog.admin.model.params.PageParam;
import com.lzw.blog.admin.pojo.Tag;
import com.lzw.blog.admin.pojo.User;
import com.lzw.blog.admin.service.RoleService;
import com.lzw.blog.admin.service.UserService;
import com.lzw.blog.admin.vo.Result;
import com.lzw.blog.admin.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;
    @PostMapping("userList")
    public Result listUser(@RequestBody PageParam pageParam) {
        return userService.listUser(pageParam);
    }

    @GetMapping("getAllRole")
    public Result getAllRole() {
        return roleService.getAllRole();
    }

    @GetMapping("setRoleForUser/{userId}")
    public Result setRoleForUser(@PathVariable Long userId, @RequestParam Long roleId) {

        return userService.setRoleForUser(userId, roleId);
    }


    @GetMapping("delete/{id}")
    public Result deleteUser(@PathVariable("id") Long id) {return userService.delete(id);}

    @PostMapping("update")
    public Result updateUser(@RequestBody User user) {

        return userService.update(user);
    }
    @PostMapping("add")
    public Result addUser(@RequestBody UserVo userVo) {
        return userService.add(userVo.getUser());
    }

    @GetMapping("totalUsers")
    public Result getNum(){return userService.getNums();}

    @GetMapping("recentUsers")
    public Result recentUsers() {
        return userService.newUsers(3);
    }
}
